package controller;

import domain.Student;
import service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addservlet")
public class AddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.获取
        String username = req.getParameter("username");
        String pwd = req.getParameter("pwd");

        //2.封装
        Student stu = new Student(null,username,pwd);

        //3.调用业务层
        StudentService service = new StudentService();
        service.add(stu);

        resp.sendRedirect("/showstudent");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
